<?php


namespace app\admin\controller;

use think\Controller;
use think\Validate;
use think\view\driver\Think;
use app\admin\controller\Log;
class Login extends Controller
{
    //管理员登录首页
    public function index(){
        session('admin',null);
        return $this->fetch();
    }
    //登录操作
    public function denglu()
    {
//        $data['captcha']=input('post.code');
//        $validate =new validate([
//            'captcha'=>'captcha'
//        ]);
//        if(!$validate->check($data)){
//        //验证失败
//            $this->error($validate->getError());
//        };

        $name=input('post.name');
        $pass=input('post.password');
//        $code=input('post.code');

        $user=db('user_admin')->where("qy_id=".session('qy_id')." and name='".$name."' and pass='". $pass."'")->find();

        if(!empty($user)){
            session('admin','123');
            session('user',$user);
            //think实例化方法
            $log= new Log();
            $log->log_xie('登录系统');
            return "<script>
                        location.href='/index.php/admin'
                        </script>";
        }else{
            return "<script>
                        alert('用户名或密码错误！');
                           setTimeout(function(){
                            location.href='/index.php/admin/login';
                        },500)
                        </script>";
        }

    }
}